package com.zzxu.androiddemo01.button;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.zzxu.androiddemo01.R;
import com.zzxu.androiddemo01.utils.DateUtil;
//防止内存泄漏
public class ButtonClickActivity extends AppCompatActivity {

    private TextView tv_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_click);
        Button button_click_single = findViewById(R.id.button_click_single);
        tv_result = findViewById(R.id.tv_result);
        button_click_single.setOnClickListener((new MyClickListener(tv_result)));
    }

    //创建一个类来实现接口
    static class MyClickListener implements View.OnClickListener {
        private final TextView tv_result;

        public MyClickListener(TextView tv_result) {
            this.tv_result=tv_result;
        }

        @Override
        public void onClick(View view) {
            String desc = String.format("%s 您点击了按钮： %s", DateUtil.getNowTime(), ((Button) view).getText());
            tv_result.setText(desc);
        }
    }

}